package main.SJdependencies;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;


import com.example.retrofit.HttpClient;
import com.example.retrofit.Log.Logs;
import com.example.retrofit.NullClass;
import com.example.retrofit.ResponseHandler;

import java.io.IOException;
import java.util.List;

import okhttp3.Interceptor;
import okhttp3.Request;
import retrofit2.Call;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //三个泛型  第一个为成功返回情况下的对象结构
        //第二个为引入的服务接口文件，
        //第三个为统一错误返回的对象结构
        //region 有统一错误返回测试
//                HttpClient<List<LoginResult>,HttpService,R_Result> _httpClient=new HttpClient(this);
//        _httpClient.setClass(HttpService.class,R_Result.class);
//        Call<List<LoginResult>> _call=_httpClient.service("http://lvmakeji.com/XYService/").Login("login","18068261236","密码登录","12346");
//        _httpClient.request(_call, new ResponseHandler<List<LoginResult>, R_Result>() {
//            @Override
//            public void onSuccess(List<LoginResult> ILoginResults) {
//
//            }
//
//            @Override
//            public void onFailure(R_Result e) {
//                Toast.makeText(MainActivity.this, e.getResult(), Toast.LENGTH_SHORT).show();
//            }
//
//            @Override
//            public void onFaileMsg(String e) {
//                Toast.makeText(MainActivity.this, e, Toast.LENGTH_SHORT).show();
//            }
//        });
        //endregion



        HttpClient<List<SalePoint>,HttpService,NullClass> _httpClient=new HttpClient(this);
        _httpClient.setClass(HttpService.class).setInterceptor(mInterceptor);
        Call<List<SalePoint>> _call=_httpClient.service("http://lvmakeji.com/XYService/").SalePoint("getSalePoint");
        _httpClient.request(_call, new ResponseHandler<List<SalePoint>, NullClass>() {
            @Override
            public void onSuccess(List<SalePoint> ISalePoints) {

            }

            @Override
            public void onFailure(NullClass e) {

            }

            @Override
            public void onFaileMsg(String e) {

            }
        });


    }
    private Interceptor mInterceptor = new Interceptor() {
        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {

            Request original = chain.request();
            Request request;
            Request.Builder builder = original.newBuilder();
            request = builder
                    .addHeader("Device", "android")
                    .build();
            okhttp3.Response response = chain.proceed(request);

            return response;
        }
    };
}
